import JsbUtil from "../../Fantasy/Util/JsbUtil";
import ServerCenter from "../../Server/ServerCenter";
import PromptManage from "../PromptManage";

const {ccclass, property} = cc._decorator;

@ccclass
export default class DialogTs extends cc.Component {

    @property(cc.Node)
    label: cc.Node = null;
    @property(cc.Prefab)
    cardPre:cc.Prefab = null


    // LIFE-CYCLE CALLBACKS:
    type;
    initDialog(str,type){
        this.label.getComponent(cc.Label).string = str ;
        this.type = type
    }
    btnCallback(target,data){
        var self = this;
        if(data == 'sure'){
            if(this.type == 1){
                JsbUtil.showVideo(()=>{
                    let random = Math.round(Math.random()*48);
                    let level = Math.floor(random / 12);
                    level = level+1;
                    let  card = cc.instantiate(self.cardPre);
                    let type = random % 12;
                    card.getComponent("StarCard").setStarCard(type,level,false);
                    ServerCenter.GetCard(type);
                    card.parent = self.node;
                });
            }else if(this.type == 2){
                JsbUtil.showVideo(()=>{
                    ServerCenter.addUserStamina(50);
                    PromptManage.addToast('获得50体力奖励');
                });            
            } 

        }else if(data == 'cancel'){
            this.node.destroy();
        }else if(data == 'close'){
            this.node.destroy();
        }
    }

}
